<template>
	<view>
		<view class="fullPage p30">
			<view class="container plr24 bf border-r1">
				<view class="flex_sb h80 ft26 bdb">
					<text>车辆编号：{{info.deviceNo || '' }}</text>
					<text>{{info.agentName || '' }}</text>
				</view>
				<view class="flex_sb h80">
					<text>{{info.siteName || ''}}</text>
					<text class="c9 ft26" v-if="(info.distance || 0)/1000 < 1">{{info.distance}}m</text>
					<text class="c9 ft26" v-else>{{(info.distance/1000).toFixed(2)}}km</text>
				</view>
				<view class="flex mb10" @click="navigation">
					<view class="flex_a w40 h40 whn"><image src="/static/ic_dw_2x.png" mode="widthFix" style="width: 22upx;height: 24upx;"></image></view>
					<text class="c9">{{info.address}}</text>
				</view>

				<view class="mb200 tae">
					<text class="plr10 primary" @click="routerLink({ path: '/pages/user/rentCar/package', query: { deviceNo: query.deviceNo, type: 1 } })">查看租车套餐</text>
				</view>

				<view class="mb50 plr30"><u-button type="primary" shape="circle" @click="routerLink({ path: '/pages/user/rentCar/package', query: { deviceNo: query.deviceNo, type: 2 } })">开始租车</u-button></view>
			</view>
		</view>
	</view>
</template>

<script>
import { getDeviceByDeviceNo,judgeCanRentCar } from '@/api/user.js'
export default {
	data() {
		return {
			query: {},
			info: {}
		}
	},
	onLoad(e) {
		this.query = e
		// this.query = { deviceNo: 112222, latitude: 23.02067, longitude: 113.75179 }
	},
	onShow() {
		this.init()
	},
	
	methods: {
		async init() {
			 this.getDeviceByDeviceNo()
			 // this.judgeCanRentCar()
			
		},
		async getDeviceByDeviceNo() {
			const res = await getDeviceByDeviceNo(this.query)
			this.info = res.data
			
			if(res.data.isOrder == 1) {
				return this.confirm({
					content: '您有正在进行中的订单',
			
					confirmText: '查看订单',
					cancelText: '返回首页'
				}).then(res => {
					if(res.confirm) {
						uni.redirectTo({
							url: '/pages/user/myOrder/index?activeTab=2'
						})
					}else {
						this.back()
					}
				})
			}
			if(res.data.carlsRent == 1) {
				return this.confirm({
					content: '当前扫描车辆已被租用，请更换车辆',
					showCancel: false
				}).then(res => {
					this.back()
				})
			}
		},
		async judgeCanRentCar() {
			const res = await judgeCanRentCar({deviceNo:this.deviceNo})
			/* if(res.code == 1001) {
				await this.confirm({
					content: res.msg,
					showCancel: false
				})
				this.back()
			} */
		},
		navigation() {
			console.log('markerInfo')
			console.log(this.info)
			uni.openLocation({
				latitude: this.info.lat * 1,
				longitude: this.info.lng * 1,
				name: this.info.siteName,
				address: this.info.address,
				success: () => {
					
				}
			})
		}
		
	}
}
</script>

<style lang="scss" scoped></style>
